const axios = require('axios');
const MockAdapter = require('axios-mock-adapter');
const normalAxios = axios.create();
const mockAxios = axios.create();
import _config from "./config";
import reqTools from "../utils/reqTools";

// 手机分类广告
var mock = new MockAdapter(mockAxios);

mock.onGet('/advPhoneType/getAll').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.get('/api/advMobileRightInfo',config.params).then(res => {
      resolve([200, res.data]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});


mock.onDelete('/advPhoneType/delete').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.delete('/api/advMobileRightInfo/'+config.id).then((res) => {
      resolve([200, res]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});

mock.onPost('/advPhoneType/add').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.post( '/api/advMobileRightInfo',config.data
    ).then((res) => {
      resolve([200, res]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});
//添加系统广告
mock.onPost('/system/advPhoneType/add').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.post( '/api/advMobileRightInfo/system_public',config.data
    ).then((res) => {
      resolve([200, res]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});

mock.onPut('/advPhoneType/update').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.put( '/api/advMobileRightInfo', config.data, 
   ).then((res) => {
      resolve([200, res ]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});

mock.onGet('/adv/getPhoneTypeById').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.get('/api/advMobileRightInfo/'+config.id).then(res => {
      resolve([200, res.data]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});
//付款/提交审核
mock.onGet('/adv/phoneType/pay').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.get('/api/advMobileRightInfo/pay',config.params).then(res => {
      resolve([200, res]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});



export default mockAxios;
